//
//  main.m
//  04-集合（二）Homeworki
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Color.h"
int main(int argc, const char * argv[]) {

    NSString *path = @"/Users/dllo/Downloads/Homework-04/crayons.txt";
    NSString *sourceStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSLog(@"%@", sourceStr);
    
//    根据\n切割字符串
    NSArray *colorStringArray = [sourceStr componentsSeparatedByString:@"\n"];
//    NSLog(@"%@",colorStringArray);
    //声明存储颜色的可变字典
    NSMutableDictionary *colorDictionary = [NSMutableDictionary dictionary];
    
    for (int i = 0; i < colorStringArray.count; i++) {
        if ([colorStringArray[i] length] > 0) {
//            NSLog(@"%@",colorStringArray[i]);
            NSArray *color = [colorStringArray[i] componentsSeparatedByString:@" #"];
            [colorDictionary setObject:[color lastObject] forKey:[color firstObject]];
        }
    }
//    NSLog(@"%@",colorDictionary);
    
    
    
    
    NSMutableDictionary *newClorDictionary = [NSMutableDictionary dictionary];
//    NSLog(@"%@",newClorDictionary);
    NSArray *allkeys = colorDictionary.allKeys;
//    NSLog(@"%@",allkeys);
    for (int i = 0; i < 100; i++) {
        NSString *subString = [allkeys[i] substringWithRange:NSMakeRange(0,1)];
        NSMutableArray *colorArray = [newClorDictionary objectForKey:subString];
//                NSLog(@"%@",subString);
//        NSLog(@"%@",colorArray);
        NSLog(@"%@",newClorDictionary);
        Color *newColor = [[Color alloc] init];
        newColor.colorName = allkeys[i];
//        NSLog(@"%@",newColor.colorName);
        newColor.colorValue = [colorDictionary objectForKey:allkeys[i]];
//        NSLog(@"%@",newColor.colorValue);
//        NSLog(@"%@",newColor);
        if (colorArray == nil) {
            colorArray = [NSMutableArray arrayWithObject:newColor];
//            NSLog(@"%@",colorArray);
            [newClorDictionary setObject:colorArray forKey:subString];
//            NSLog(@"%@",newClorDictionary);
        }else
        {
            [colorArray addObject:newColor];
//            NSLog(@"%@",colorArray);
        }
    }
    
    
//    NSLog(@"%@",newClorDictionary);
    
    
//    NSMutableDictionary *dic7 = [NSMutableDictionary dictionary];
//    NSMutableString *arr5 = [NSMutableString string];
//    NSDictionary *dic5 = @{@"1":@"a",@"2":@"b"};
//    NSMutableArray *arr = [dic5 allKeys];
//    
//    for (NSString *str in arr) {
//        
//      arr5 = [dic5 objectForKey:str];
//    NSString *arr6 = [arr5 stringByAppendingString:@"&"];
//        
////        NSLog(@"%@",arr6);
//    }
////    
//    NSArray *d = @[@"wq",@"oi",@"fg",@"c",@"cxdgffdjkghdjkfng"];
//    NSString *a = @"dfs";
//    NSString *b = @"nv";
//    for (NSString *str in d) {
//        
//    NSString *c = [str stringByAppendingString:str];
////        NSLog(@"%@",c);
//    }
//    
//    
//    NSString *str6 = [NSString string];
//    NSString *str1 = [NSString string];
//    for (NSString *str in d) {
////        NSLog(@"%@",str);
//        str6 = [str6 stringByAppendingString:str];
//    }
//    NSLog(@"%@",str6);

//    NSMutableString *str7 = [[NSMutableString alloc] initWithFormat:@"qwsfsdfscv"];
//    NSArray *arr8 = [NSArray array];
//    arr8 = [str7 componentsSeparatedByString:@"f"];
//    NSLog(@"%@",arr8);
//    arr8 = [str7 componentsSeparatedByString:@"s"];
//    NSLog(@"%@",arr8);
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}
